package org.linlinjava.litemall.db.dao;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

import com.github.yulichang.base.MPJBaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.linlinjava.litemall.db.domain.LitemallBrowseRecord;
import org.linlinjava.litemall.db.domain.LitemallBrowseRecordExample;
import org.linlinjava.litemall.db.dto.AdminGoodsBrowserDTO;

public interface LitemallBrowseRecordMapper extends MPJBaseMapper<LitemallBrowseRecord> {
    long countByExample(LitemallBrowseRecordExample example);

    int deleteByExample(LitemallBrowseRecordExample example);

    int deleteByPrimaryKey(Integer id);

    int insert(LitemallBrowseRecord record);

    int insertSelective(LitemallBrowseRecord record);

    LitemallBrowseRecord selectOneByExample(LitemallBrowseRecordExample example);

    LitemallBrowseRecord selectOneByExampleSelective(@Param("example") LitemallBrowseRecordExample example, @Param("selective") LitemallBrowseRecord.Column ... selective);

    List<LitemallBrowseRecord> selectByExampleSelective(@Param("example") LitemallBrowseRecordExample example, @Param("selective") LitemallBrowseRecord.Column ... selective);

    List<LitemallBrowseRecord> selectByExample(LitemallBrowseRecordExample example);

    LitemallBrowseRecord selectByPrimaryKeySelective(@Param("id") Integer id, @Param("selective") LitemallBrowseRecord.Column ... selective);

    LitemallBrowseRecord selectByPrimaryKey(Integer id);

    LitemallBrowseRecord selectByPrimaryKeyWithLogicalDelete(@Param("id") Integer id, @Param("andLogicalDeleted") boolean andLogicalDeleted);

    int updateByExampleSelective(@Param("record") LitemallBrowseRecord record, @Param("example") LitemallBrowseRecordExample example);

    int updateByExample(@Param("record") LitemallBrowseRecord record, @Param("example") LitemallBrowseRecordExample example);

    int updateByPrimaryKeySelective(LitemallBrowseRecord record);

    int updateByPrimaryKey(LitemallBrowseRecord record);

    int logicalDeleteByExample(@Param("example") LitemallBrowseRecordExample example);

    int logicalDeleteByPrimaryKey(Integer id);

    @Select("SELECT\n" +
            "    gd.name,\n" +
            "    br.goods_id,\n" +
            "    COUNT(br.goods_id) AS goodsNum,\n" +
            "    COUNT(DISTINCT br.browse_user_id) AS userNum\n" +
            "FROM\n" +
            "    litemall_browse_record br\n" +
            "JOIN\n" +
            "    litemall_goods gd ON br.goods_id = gd.id\n" +
            "WHERE\n" +
            "    DATE(br.add_time) = DATE(#{day})\n" +
            "GROUP BY\n" +
            "    gd.name,\n" +
            "    br.goods_id;")
    List<AdminGoodsBrowserDTO> goodsBrowser(LocalDateTime day);
}